﻿@model Sheng.Enterprise.Web.Models.SearchByWorkTypeViewModel

@{
    ViewBag.Title = "查询";
    Layout = "~/Views/Shared/_Layout.cshtml";

    ViewBag.LeftTitle = "周 报";
    ViewBag.MainMenu = "WeeklyReport";
    ViewBag.LeftMenu = "Search";
}


<script>

    var _workType = getQueryString('workType');
    var _workTask = getQueryString('workTask');

    $(document).ready(function () {

        $("#selectYear").val(@Model.Year);
        $("#selectMonth").val(@Model.Month);

        $('#selectYear').change(function () {
            search();
        });
        $('#selectMonth').change(function () {
            search();
        });

        $('#selectWorkType').change(function () {
            loadWorkTaskList();
        });

        //    alert(_workType);
        if (_workType != undefined && _workType != null && _workType != '') {
            $('#selectWorkType').val(_workType);
        }

        loadWorkTaskList();

        if (_workTask != undefined && _workTask != null && _workTask != '') {
            $('#selectWorkTask').val(_workTask);
        }

        //在打开的iframe中修改了organizationSelector后，虽然这边能响应
        //但是无法执行  window.location.href ，提示没有权限
        //$("#organizationSelector").change(function ()
        //{
        //    search();
        //});

        $("#chkSelectAll").change(function () {


            if ($("#chkSelectAll").is(':checked')) {
                $(".weeklyReportItem").each(function (index, element) {
                    $(element).prop("checked", true);
                })
            } else {
                $(".weeklyReportItem").each(function (index, element) {
                    $(element).prop("checked", false);
                })
            }
        });

        $(".weeklyReportItem").change(function () {
            
            var checkedCount = 0;
            $(".weeklyReportItem").each(function (index, element) {
                if ($(element).is(':checked')) {
                    checkedCount++;
                }
            });

            if($(".weeklyReportItem").length == checkedCount){
                $("#chkSelectAll").prop("checked", true);
            }else{
                $("#chkSelectAll").prop("checked", false);
            }

        });
    });

    function loadWorkTaskList() {
        $("#selectWorkTask").empty();
        var workTypeId = $("#selectWorkType").val();

        var optionObj = new Option('--全部--', '', true, false);
        document.getElementById('selectWorkTask').options.add(optionObj);

        @foreach (var item in Model.WorkTaskList)
        {
            <text>
        if ('@item.WorkType' == workTypeId) {
            var optionObj = new Option('@item.Name', '@item.Id', true, false);
            document.getElementById('selectWorkTask').options.add(optionObj);
        }
        </text>
        }
    }

    function search() {
        layer.load(0, {
            shade: [0.2, '#fff']
        });

        var workType = $("#selectWorkType").val();
        var workTask = $("#selectWorkTask").val();
        var year = $("#selectYear").val();
        var month = $("#selectMonth").children('option:selected').val();
        var week = '@Model.WeekOfYear';
        window.location.href = "/WeeklyReport/SearchByWorkType?year=" + year + "&month=" + month
            + "&week=" + week + "&workType=" + workType + "&workTask=" + workTask;
    }

    function switchWeek(week) {
        layer.load(0, {
            shade: [0.2, '#fff']
        });

        var workType = $("#selectWorkType").val();
        var workTask = $("#selectWorkTask").val();
        var year = $("#selectYear").val();
        var month = $("#selectMonth").children('option:selected').val();
        window.location.href = "/WeeklyReport/SearchByWorkType?year=" + year + "&month=" + month
            + "&week=" + week + "&workType=" + workType + "&workTask=" + workTask;
    }

    function exportToExcel() {

        var userList = new Array();
        var i = 0;
        $(".weeklyReportItem").each(function (index, element) {
            if ($(element).is(':checked')) {
                userList[i] = $(element).attr("user");;
                i++;
            }
        });

        if(userList.length==0){
            layerAlert("请选择要下载的周报条目。");
            return;
        }

        //startYear, startMonth, endYear, endMonth

        var args = new Object();
        args.Year = @Model.Year;
        args.WeekOfYear = @Model.WeekOfYear;
        args.WorkType = $("#selectWorkType").val();
        args.WorkTask = $("#selectWorkTask").val();
        args.UserList = userList;

        var layerIndex = layer.load(0, {
            shade: [0.2, '#fff']
        });

        $.ajax({
            url: "/Api/WeeklyReport/ExportByWorkType",
            data:JSON.stringify(args),
            type: "POST",
            dataType: "json",
            success: function (data, status, jqXHR) {
                layer.close(layerIndex);
                if(data.Success){
                    //    alert(JSON.stringify(data));

                    window.location.href="/ExcelExport/" + data.Data;

                }else{
                    layerAlert(data.Message);
                }
            },
            error: function (xmlHttpRequest) {
                layer.close(layerIndex);
                alert("Error: " + xmlHttpRequest.status);
            }
        });
    }

</script>

<div style="margin-right:20px;margin-bottom:20px;">
    @Helpers.TitleWithDate("查询", this.ViewBag)
    <div style="margin-top:20px">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td class="td_ContentTab">
                    @Html.ActionLink("按个人", "SearchByPersonal", "WeeklyReport", null, new { @class = "a_black_16" })
                </td>
                @if (AuthorizationHelper.Verify("WeeklyReport_SearchByOrganization", HttpContext.Current))
                {
                    <td class="td_ContentTab">
                        @Html.ActionLink("按组织架构", "SearchByOrganization", "WeeklyReport", null, new { @class = "a_black_16" })
                    </td>
                }
                <td class="td_ContentTab_active">按项目</td>
                <td>&nbsp;</td>
            </tr>
            <tr>
                <td colspan="4" bgcolor="#D4D4D4" height="1"></td>
            </tr>
        </table>

    </div>
    <div style="margin-top:20px; height:32px;">
        @*<div style="float:left; line-height:32px;">
                组织架构：
            </div>
            <div style="float:left; margin-left:20px;">
                @Helpers.OrganizationSelector("organizationSelector", null, null, ViewBag.Domain.Id, ViewBag.Domain.Name)
            </div>*@
        <div style="float:left; line-height:32px;">
            项目：
        </div>
        <div style="float:left; margin-left:20px;">
            <select class="input_18" id="selectWorkType">
                @*<option value="">--全部--</option>*@
                @foreach (var item in Model.WorkTypeList)
                {
                    <option value="@item.Id">@item.Name</option>
                }
            </select>
        </div>
        <div style="float:left; line-height:32px;margin-left:20px;">
            子项目：
        </div>
        <div style="float:left; margin-left:20px;">
            <select class="input_18" id="selectWorkTask">
                <option value="">--全部--</option>
            </select>
        </div>
        <div style="float:left; line-height:34px;margin-left:20px;">
            <input name="btnSearch" type="button" class="btn_blue" id="btnSearch" value="查询" onclick="search()" />
            <input name="btnExportToExcel" type="button" class="btn_blue" id="btnExportToExcel" value="下载" onclick="exportToExcel()" />
        </div>
    </div>
    <div style="height:50px;background:#D8E6ED; margin-top:20px;">
        <div style="float:left; margin-left:20px; margin-right:20px">
            <table border="0" cellspacing="0" cellpadding="0" height="50">
                <tr>
                    <td>
                        <select id="selectYear" class="input_18">
                            @foreach (var item in ViewBag.YearList)
                            {
                                <option>@item</option>
                            }
                        </select>
                    </td>
                    <td width="15">
                        &nbsp;

                    </td>
                    <td>
                        <select id="selectMonth" class="input_18">
                          
                            @if (Model.Year == DateTime.Now.Year)
                            {
                                for (int i = 1; i < 12; i++)
                                {
                                    if (i > DateTime.Now.Month)
                                    {
                                        break;
                                    }

                                    <option>@i</option>
                                }
                            }
                            else
                            {
                                <option>1</option>
                                <option>2</option>
                                <option>3</option>
                                <option>4</option>
                                <option>5</option>
                                <option>6</option>
                                <option>7</option>
                                <option>8</option>
                                <option>9</option>
                                <option>10</option>
                                <option>11</option>
                                <option>12</option>
                            }

                        </select>
                    </td>
                </tr>
            </table>
        </div>
        @*<div class="weekTab">
                <a href="#">6/29 - 7/5</a>
            </div>
            <div class="weekTab">
                <a href="#">7/6 - 7/12</a>
            </div>
            <div class="weekTab weekTab_active">
                7/13 - 7/19
            </div>
            <div class="weekTab">
                <a href="#">7/20 - 7/26 </a>
            </div>
            <div class="weekTab">
                <a href="#">7/27 - 8/6</a>
            </div>*@
        @foreach (var item in Model.WeekList)
        {
            if (Model.Year == DateTime.Now.Year && item.WeekOfYear > Model.CurrentWeekOfYear)
            {
                break;
            }

            <div class="weekTab  @if (item.WeekOfYear == Model.WeekOfYear)
                {
                    @Html.Raw("weekTab_active")
                }">
                @if (item.WeekOfYear == Model.WeekOfYear)
                {
                    @Html.Raw(item.Monday.ToString("MM/dd") + " - " + item.Sunday.ToString("MM/dd") + (Model.Year == DateTime.Now.Year && item.WeekOfYear == Model.CurrentWeekOfYear ? "（本周）" : ""))
                }
                else
                {
                    @Html.Raw("<a href='javascript:void(0);' onclick=\"switchWeek(\'" + item.WeekOfYear + "\')\">" + item.Monday.ToString("MM/dd") + " - " + item.Sunday.ToString("MM/dd") + (Model.Year == DateTime.Now.Year && item.WeekOfYear == Model.CurrentWeekOfYear ? "（本周）" : "") + "</a>");
                }
            </div>
        }
    </div>

    <div>

        <div style="float:right">
            <input type="checkbox" id="chkSelectAll" /><label for="chkSelectAll">全选</label>
        </div>
        <div style="clear:both"></div>
    </div>

    @{
        foreach (var weeklyReport in Model.WeeklyReportList)
        {
            if (weeklyReport.ItemList.Count == 0)
            {
                continue;
            }

            <div style="margin-top:20px;">
                <div>
                     <div>
                        <div class="font_darkBlue_22" style="float:left">
                            @weeklyReport.UserName  <span class="font_blue_18">- @weeklyReport.OrganizationName</span>
                        </div>
                        <div style="float:right">
                            <input type="checkbox" class="weeklyReportItem" user="@weeklyReport.User" />
                        </div>
                        <div style="clear:both"></div>
                    </div>

                    <div class="divSearchWeeklyReportContainer">
                        <table width="100%" border="0" cellspacing="0" cellpadding="0" style="Word-break: break-all">
                            <tr>
                                <td width="150"><strong>组别</strong></td>
                                <td width="150"><strong>项目名称</strong></td>
                                <td width="190"><strong>子项目</strong></td>
                                <td><strong>工作内容</strong></td>
                                <td width="110"><strong>完成情况</strong></td>
                                <td width="110"><strong>日期</strong></td>
                                @*<td width="150"><strong>备注</strong></td>*@
                                @*<td width="50"><strong>用时</strong></td>*@
                            </tr>
                            <tr>
                                <td colspan="7" height="20"><div style="background:#D4D4D4; height:1px;"></div></td>
                            </tr>
                            @foreach (var item in weeklyReport.ItemList)
                            {
                                <tr>
                                    <td class="tdSearchWeeklyReportItem">@item.OrganizationName</td>
                                    <td class="tdSearchWeeklyReportItem">@item.WorkTypeName</td>
                                    <td class="tdSearchWeeklyReportItem">@item.WorkTaskName</td>
                                    <td class="tdSearchWeeklyReportItem">@Html.Raw(item.Content)</td>
                                    <td class="tdSearchWeeklyReportItem">@item.StatusName</td>
                                    <td class="tdSearchWeeklyReportItem">@if (item.Date.HasValue) {@item.Date.Value.ToString("yyyy-MM-dd") }</td>
                                    <td class="tdSearchWeeklyReportItem">@*@Html.Raw(item.Remark)*@</td>
                                    @*<td class="tdSearchWeeklyReportItem">@item.Time</td>*@
                                </tr>
                            }
                        </table>

                        @if (weeklyReport.Checked)
                        {
                            <div id="divCheckResult" style=" margin-top:20px;">
                                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                    <tr>
                                        <td>已阅</td>
                                    </tr>
                                    @*<tr>
                                        <td valign="top">
                                            <div>
                                                @foreach (var item in weeklyReport.CheckPointList)
                                                {
                                                    <div style="float:left; line-height:34px;margin-right:20px;">
                                                        @item.CheckPointName：@item.CheckPointItemName（@item.Score）
                                                    </div>
                                                }
                                            </div>
                                        </td>
                                    </tr>
                                    @if (String.IsNullOrEmpty(weeklyReport.CheckRemark) == false)
                                    {
                                        <tr>
                                            <td valign="bottom" height="10"></td>
                                        </tr>
                                        <tr>
                                            <td valign="top">
                                                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                                    <tr>
                                                        <td width="100">审核意见：</td>
                                                        <td>@weeklyReport.CheckRemark</td>
                                                    </tr>
                                                </table>
                                            </td>
                                        </tr>
                                    }*@
                                </table>
                            </div>
                        }


                    </div>
                </div>
            </div>


        }
    }
    <div>
    </div>
</div>
